#include<bits/stdc++.h>
using namespace std;
int main() {
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    scanf("%d",&T);
JustDoEat:
    while(T--) {
        int n,m,L,V,li[114514],cnt = 000,cscar[114514],csn = 0;
        bool a0 = 1;
        scanf("%d%d%d%d",&n, &m, &L, &V);
        for(int i = 1; i <= n; ++ i) {
            int d,v,a,chao = 0;
            scanf("%d%d%d",&d,&v,&a);
            if(v > V) cscar[++cnt] = d;
        }
        int maxn = INT_MIN;
        for(int i = 1; i <= m; ++ i) {
            scanf("%d",&li[i]);
            maxn = max(maxn , li[i]);
        }
        int ans = 0;
        for(int i = 1; i <= cnt; ++ i) {
            if(cscar[i] <= maxn) {
                csn++;
                if(ans == 0) ans = m - 1;
            }
        }
        if(ans == 0) ans = m;
        cout << csn << ' ' << ans << "\n";

    }
    return 0;
}
